<?php
require "../factory/lib/shape.php";
require "../factory/lib/color.php";

interface AbstractFactory
{
    /** @return Shape */
    public function getShape();
    /** @return Color */
    public function getColor();
}
class AlphaFactory implements AbstractFactory
{
    public function getShape()
    {
        return new Rectangle;
    }
    public function getColor()
    {
        return new Red;
    }
}
class BetaFactory implements AbstractFactory
{
    public function getShape()
    {
        return new Circle;
    }
    public function getColor()
    {
        return new Blue;
    }
}
class FactoryProducer
{
    /** @return AbstractFactory */
    public function getFactory($choice)
    {
        $type=strtolower($choice);
        $factory=null;
        switch ($type) {
            case 'alpha':
                $factory = new AlphaFactory;
                break;
            case 'beta':
                $factory = new BetaFactory;
                break;
        }
        return $factory;
    }
}

header('Content-Type: text/plain');

$producer=new FactoryProducer;

$alpha=$producer->getFactory("alpha");
$alpha->getShape()->draw();
$alpha->getColor()->fill();

$beta=$producer->getFactory("beta");
$beta->getShape()->draw();
$beta->getColor()->fill();
